package org.jeecg.modules.demo.hydrology.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.jeecg.modules.demo.hydrology.dto.DhssDto;
import org.jeecg.modules.demo.hydrology.entity.Cgkcdss;
import org.jeecg.modules.demo.hydrology.entity.Pslcdss;
import org.jeecg.modules.demo.hydrology.mapper.*;
import org.jeecg.modules.demo.hydrology.service.IDhssService;
import org.jeecg.modules.system.entity.SysDict;
import org.jeecg.modules.system.entity.SysDictItem;
import org.jeecg.modules.system.mapper.SysDictItemMapper;
import org.jeecg.modules.system.mapper.SysDictMapper;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class DhssServiceImpl implements IDhssService {
    @Autowired
    private DbcxcdssMapper dbcxcdssMapper;
    @Autowired
    private CgkcdssMapper cgkcdssMapper;
    @Autowired
    private CscdssMapper cscdssMapper;
    @Autowired
    private PslcdssMapper pslcdssMapper;
    @Autowired
    private DbscdssMapper dbscdssMapper;
    @Autowired
    private WzcdssMapper wzcdssMapper;
    @Autowired
    private JslcdssMapper jslcdssMapper;
    @Autowired
    private YslcdssMapper yslcdssMapper;
    @Autowired
    private SysDictMapper sysDictMapper;
    @Autowired
    private SysDictItemMapper sysDictItemMapper;

    /**
     * 井下传感器 实时监测查询
     * @param stationCode
     * @return
     */
    @Override
    public DhssDto getDhss(String stationCode) {
        DhssDto dhssDto = new DhssDto();
        // 井下传感器 长观孔实时监测
        Cgkcdss cgkcdss = cgkcdssMapper.getByCode(stationCode);
        if (cgkcdss != null && "001-B801".equals(stationCode)){
            BeanUtils.copyProperties(cgkcdss,dhssDto);
            QueryWrapper<SysDict> sysDictQueryWrapper = new QueryWrapper<>();
            sysDictQueryWrapper.eq("dict_code","point_status");
            SysDict sysDict = sysDictMapper.selectOne(sysDictQueryWrapper);
            if (sysDict != null){
                QueryWrapper<SysDictItem> sysDictItemQueryWrapper = new QueryWrapper<>();
                sysDictItemQueryWrapper.eq("dict_id",sysDict.getId()).eq("item_value",cgkcdss.getPointStatus());
                SysDictItem sysDictItem = sysDictItemMapper.selectOne(sysDictItemQueryWrapper);
                if (sysDictItem != null) {
                    dhssDto.setStationStatus(sysDictItem.getItemText());
                }
            }
            dhssDto.setEquipmentLocation(cgkcdss.getLocation());
            dhssDto.setValue(cgkcdss.getWaterLevel().toString());
            dhssDto.setUnit("米");
            dhssDto.setSensorType("水位");
        }
        if (cgkcdss != null && "001-B802".equals(stationCode)){
            BeanUtils.copyProperties(cgkcdss,dhssDto);
            QueryWrapper<SysDict> sysDictQueryWrapper = new QueryWrapper<>();
            sysDictQueryWrapper.eq("dict_code","point_status");
            SysDict sysDict = sysDictMapper.selectOne(sysDictQueryWrapper);
            if (sysDict != null){
                QueryWrapper<SysDictItem> sysDictItemQueryWrapper = new QueryWrapper<>();
                sysDictItemQueryWrapper.eq("dict_id",sysDict.getId()).eq("item_value",cgkcdss.getPointStatus());
                SysDictItem sysDictItem = sysDictItemMapper.selectOne(sysDictItemQueryWrapper);
                if (sysDictItem != null) {
                    dhssDto.setStationStatus(sysDictItem.getItemText());
                }
            }
            dhssDto.setEquipmentLocation(cgkcdss.getLocation());
            dhssDto.setValue(cgkcdss.getWaterTemperature().toString());
            dhssDto.setUnit("度");
            dhssDto.setSensorType("水温");
        }
        if (cgkcdss != null && "001-B701".equals(stationCode)){
            BeanUtils.copyProperties(cgkcdss,dhssDto);
            QueryWrapper<SysDict> sysDictQueryWrapper = new QueryWrapper<>();
            sysDictQueryWrapper.eq("dict_code","point_status");
            SysDict sysDict = sysDictMapper.selectOne(sysDictQueryWrapper);
            if (sysDict != null){
                QueryWrapper<SysDictItem> sysDictItemQueryWrapper = new QueryWrapper<>();
                sysDictItemQueryWrapper.eq("dict_id",sysDict.getId()).eq("item_value",cgkcdss.getPointStatus());
                SysDictItem sysDictItem = sysDictItemMapper.selectOne(sysDictItemQueryWrapper);
                if (sysDictItem != null) {
                    dhssDto.setStationStatus(sysDictItem.getItemText());
                }
            }
            dhssDto.setEquipmentLocation(cgkcdss.getLocation());
            dhssDto.setValue(cgkcdss.getWaterLevel().toString());
            dhssDto.setUnit("米");
            dhssDto.setSensorType("水位");
        }
        if (cgkcdss != null && "001-B702".equals(stationCode)){
            BeanUtils.copyProperties(cgkcdss,dhssDto);
            QueryWrapper<SysDict> sysDictQueryWrapper = new QueryWrapper<>();
            sysDictQueryWrapper.eq("dict_code","point_status");
            SysDict sysDict = sysDictMapper.selectOne(sysDictQueryWrapper);
            if (sysDict != null){
                QueryWrapper<SysDictItem> sysDictItemQueryWrapper = new QueryWrapper<>();
                sysDictItemQueryWrapper.eq("dict_id",sysDict.getId()).eq("item_value",cgkcdss.getPointStatus());
                SysDictItem sysDictItem = sysDictItemMapper.selectOne(sysDictItemQueryWrapper);
                if (sysDictItem != null) {
                    dhssDto.setStationStatus(sysDictItem.getItemText());
                }
            }
            dhssDto.setEquipmentLocation(cgkcdss.getLocation());
            dhssDto.setValue(cgkcdss.getWaterTemperature().toString());
            dhssDto.setUnit("度");
            dhssDto.setSensorType("水温");
        }
        // 井下传感器 排水量实时监测
        Pslcdss pslcdss = pslcdssMapper.getByCode(stationCode);
        if (pslcdss != null && "001-A102".equals(stationCode)) {
            BeanUtils.copyProperties(pslcdss,dhssDto);
            QueryWrapper<SysDict> sysDictQueryWrapper = new QueryWrapper<>();
            sysDictQueryWrapper.eq("dict_code","point_status");
            SysDict sysDict = sysDictMapper.selectOne(sysDictQueryWrapper);
            if (sysDict != null){
                QueryWrapper<SysDictItem> sysDictItemQueryWrapper = new QueryWrapper<>();
                sysDictItemQueryWrapper.eq("dict_id",sysDict.getId()).eq("item_value",pslcdss.getStationStatus());
                SysDictItem sysDictItem = sysDictItemMapper.selectOne(sysDictItemQueryWrapper);
                if (sysDictItem != null) {
                    dhssDto.setStationStatus(sysDictItem.getItemText());
                }
            }
            dhssDto.setEquipmentLocation(pslcdss.getLocation());
            dhssDto.setValue(pslcdss.getValue().toString());
            dhssDto.setUnit("m3");
            dhssDto.setSensorType("累积流量");
        }
        if (pslcdss != null && "001-A101".equals(stationCode)) {
            BeanUtils.copyProperties(pslcdss,dhssDto);
            QueryWrapper<SysDict> sysDictQueryWrapper = new QueryWrapper<>();
            sysDictQueryWrapper.eq("dict_code","point_status");
            SysDict sysDict = sysDictMapper.selectOne(sysDictQueryWrapper);
            if (sysDict != null){
                QueryWrapper<SysDictItem> sysDictItemQueryWrapper = new QueryWrapper<>();
                sysDictItemQueryWrapper.eq("dict_id",sysDict.getId()).eq("item_value",pslcdss.getStationStatus());
                SysDictItem sysDictItem = sysDictItemMapper.selectOne(sysDictItemQueryWrapper);
                if (sysDictItem != null) {
                    dhssDto.setStationStatus(sysDictItem.getItemText());
                }
            }
            dhssDto.setEquipmentLocation(pslcdss.getLocation());
            dhssDto.setValue(pslcdss.getValue().toString());
            dhssDto.setUnit("m3/h");
            dhssDto.setSensorType("瞬时排水量");
        }
        if (pslcdss != null && "001-A202".equals(stationCode)) {
            BeanUtils.copyProperties(pslcdss,dhssDto);
            QueryWrapper<SysDict> sysDictQueryWrapper = new QueryWrapper<>();
            sysDictQueryWrapper.eq("dict_code","point_status");
            SysDict sysDict = sysDictMapper.selectOne(sysDictQueryWrapper);
            if (sysDict != null){
                QueryWrapper<SysDictItem> sysDictItemQueryWrapper = new QueryWrapper<>();
                sysDictItemQueryWrapper.eq("dict_id",sysDict.getId()).eq("item_value",pslcdss.getStationStatus());
                SysDictItem sysDictItem = sysDictItemMapper.selectOne(sysDictItemQueryWrapper);
                if (sysDictItem != null) {
                    dhssDto.setStationStatus(sysDictItem.getItemText());
                }
            }
            dhssDto.setEquipmentLocation(pslcdss.getLocation());
            dhssDto.setValue(pslcdss.getValue().toString());
            dhssDto.setUnit("m3");
            dhssDto.setSensorType("累积流量");
        }
        if (pslcdss != null && "001-A201".equals(stationCode)) {
            BeanUtils.copyProperties(pslcdss,dhssDto);
            QueryWrapper<SysDict> sysDictQueryWrapper = new QueryWrapper<>();
            sysDictQueryWrapper.eq("dict_code","point_status");
            SysDict sysDict = sysDictMapper.selectOne(sysDictQueryWrapper);
            if (sysDict != null){
                QueryWrapper<SysDictItem> sysDictItemQueryWrapper = new QueryWrapper<>();
                sysDictItemQueryWrapper.eq("dict_id",sysDict.getId()).eq("item_value",pslcdss.getStationStatus());
                SysDictItem sysDictItem = sysDictItemMapper.selectOne(sysDictItemQueryWrapper);
                if (sysDictItem != null) {
                    dhssDto.setStationStatus(sysDictItem.getItemText());
                }
            }
            dhssDto.setEquipmentLocation(pslcdss.getLocation());
            dhssDto.setValue(pslcdss.getValue().toString());
            dhssDto.setUnit("m3/h");
            dhssDto.setSensorType("瞬时排水量");
        }
        return dhssDto;
    }
}
